package com.so.component.remote;

import com.so.component.CommonComponent;
import com.so.entity.ConnectionInfo;
import com.so.ui.ComponentFactory;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.VaadinSession;
import com.vaadin.ui.BrowserFrame;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

/**
 * 引入一个xterm终端
 */
@Service
@Scope("prototype")
public class RemoteSSHXterm extends CommonComponent {

    private Panel mainPanel;
    private VerticalLayout contentLayout;
    private ConnectionInfo addr;
    private String hostName;
    @Override
    public void initLayout() {
        mainPanel = new Panel();
        contentLayout = new VerticalLayout();
        setCompositionRoot(mainPanel);
        mainPanel.setContent(contentLayout);
        contentLayout.setWidth("100%");
        contentLayout.setHeight("700px");
        initMainLayout();
    }

    private void initMainLayout() {
        BrowserFrame terminal = new BrowserFrame(null, new ExternalResource("VAADIN/themes/mytheme/terminal.html"));
        terminal.setSizeFull();
        contentLayout.addComponent(terminal);
        contentLayout.addComponent(ComponentFactory.getStandardLabel("该终端仅限于临时使用，暂不支持vim/tail -f /以及组合按键等操作，若无法退出则关闭当前tab，重新打开即可"));
        contentLayout.setExpandRatio(terminal, 1.0f);
    }

    @Override
    public void initContent() {

    }

    @Override
    public void registerHandler() {

    }

    public ConnectionInfo getAddr() {
        return addr;
    }

    public void setAddr(ConnectionInfo addr) {
        this.addr = addr;
    }

    public String getHostName() {
        return hostName;
    }

    public void setHostName(String hostName) {
        this.hostName = hostName;
    }
}
